
package nccloud.web.arap.amortization.action.base;

import java.util.ArrayList;
import java.util.List;

import nc.vo.pubapp.pattern.model.entity.bill.IBill;
import nccloud.framework.core.exception.ExceptionUtils;

/**
* @description 基础删除Action
* @version ncc1.0
*/
public abstract class BaseDeleteAction extends BaseBatchOperateAction {

    @Override
    public BaseBatchResult batchOperate(Object[] objs) {
        IBill[] bills = (IBill[]) objs;
        // 构建删除结果
        BaseBatchResult result = new BaseBatchResult();
        if (bills.length == 1) {
            this.delete(bills[0]);
            result.setMessage(
            nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4009012_0", "04009012-0021")/*
            * @ res "删除成功！"
            */);
            result.setSuccessIds(new String[] { bills[0].getParent().getPrimaryKey() });
        } else {
            List<String> ids = new ArrayList<String>();
            List<String> msg = new ArrayList<String>();
            for (int i = 0; i < bills.length; i++) {
                try {
                    this.delete(bills[i]);
                } catch (Exception e) {
                    Throwable throwable = ExceptionUtils.unmarsh(e);
                    String errMsg = throwable.getMessage();
                    msg.add(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4009012_0", "04009012-0022", null,
                    new String[] { String.valueOf(i + 1) })/* @res "第{0}条记录失败：" */
                    + errMsg);
                }
                ids.add(bills[i].getParent().getPrimaryKey());
            }
                result.setErrMsg(msg.toArray(new String[0]));
                result.setSuccessIds(ids.toArray(new String[0]));
        }
        return result;
    }

    /**
    *
    * 删除
    *
    * @param bill
    *
    */
    public abstract void delete(IBill bill);

}
